package com.hsteach.service.myopia;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hsteach.dao.domain.myopia.MyopiaMission;
import com.hsteach.dao.domain.myopia.MyopiaRisk;
import com.hsteach.dao.mapper.MyopiaRiskMapper;
import com.hsteach.web.controller.myopia.vo.MyopiaRiskVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 近视高危service
 *
 * @author lx
 * @date 2023-07-07
 */
@Service
public class MyopiaRiskService extends ServiceImpl<MyopiaRiskMapper, MyopiaRisk> {

    @Autowired
    private MyopiaRiskMapper riskMapper;

    @Autowired
    private MyopiaMissionService missionService;

    @Autowired
    private MyopiaService myopiaService;

    public List<MyopiaRiskVO> getRiskProportion(Long schoolId) {
        return riskMapper.getRiskProportion(schoolId);
    }

    public List<MyopiaRiskVO> getAreaRiskProportion(Integer type) {
        String groupBy = type.equals(1)?"r.grade":"r.school_id";
        MyopiaMission mission = missionService.getNewMission();
        if (mission == null){
            return new ArrayList<>();
        }
        return riskMapper.getAreaRiskProportion(mission.getId(), groupBy);
    }
}
